package org.lzuploader.model;

import java.io.Serializable;

/** This class contains all information needed to identify and connect to a server.
 * 
 * @author Emmanuel Cron
 *
 */
public class Server implements Serializable
{
    /** Serial UID of this class. */
    private static final long serialVersionUID = 8337235465719470874L;

    /** Id of this server.
     * The id is usually a specific name used by the calling program.
     */
    private String id;
    
    /** Address of the server.
     * Adress of the server, either an IP or a server name.
     */
    private String address;
    /** Port on which to connect to (by default: 80). */
    private int port = 80;
    /** Path at which the roster is installed. */
    private String path;
    
    /** Creates a new server with a specific id.
     * @param serverId The id of this server.
     */
    public Server(final String serverId)
    {
        id = serverId;
    }
    
    /** Returns the id of this server.
     * @return A string containing the id of this server.
     */
    public String getId()
    {
        return id;
    }
    
    /** Returns the address of the server.
     * @return The address of the server, either an IP or a name.
     */
    public String getAddress()
    {
        return address;
    }
    
    /** Returns the port on which to connect to.
     * @return The port on which to connect to.
     */
    public int getPort()
    {
        return port;
    }
    
    /** Returns the path at which the roster is installed.
     * @return The path where the roster can be found.
     */
    public String getPath()
    {
        return path;
    }
    
    /** Sets the address of the server.
     * @param newAddress The new address to set for this server.
     */
    public void setAddress(final String newAddress)
    {
        address = newAddress;
    }
    
    /** Sets the port on which to connect to.
     * @param newPort The port on which to connect to.
     */
    public void setPort(final int newPort)
    {
        port = newPort;
    }
    
    /** Sets the path at which the roster can be found.
     * @param newPath A path relative to the server's root (/).
     */
    public void setPath(final String newPath)
    {
        path = newPath;
    }
    
    /** This function returns information about the server within a String.
     * @return String
     */
    @Override
    public String toString()
    {
        return id.toString() + " { " + address.toString() + ":" + port + path.toString() + " }";
    }
}
